package org.groupg.filetodb.model;

import cn.hutool.core.date.TimeInterval;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import org.groupg.filetodb.model.finals.TaskRunningStatus;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class TaskRunning {
    /**
     * 处理的任务配置
     */
    private Task task;
    /**
     * 任务编号
     */
    private String runId;
    /**
     * 任务执行状态
     */
    private TaskRunningStatus status = TaskRunningStatus.READY;
    /**
     * 时间计时器
     */
    private TimeInterval interval = new TimeInterval();
    /**
     * 启动时间
     */
    private LocalDateTime startTime;
    /**
     * 结束时间
     */
    private LocalDateTime endTime;
    /**
     * 时间间隔
     */
    private long duration;
    /**
     * 说明
     */
    private String desc;

    /**
     * 本任务
     */
    private final List<TableRunning> tableWriter = new ArrayList<>();

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("task", task)
                .add("runId", runId)
                .add("status", status)
                .add("interval", interval)
                .add("startTime", startTime)
                .add("endTime", endTime)
                .add("duration", duration)
                .add("desc", desc)
//                .add("tableWriter", tableWriter.size())
                .toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        TaskRunning that = (TaskRunning) o;
        return getDuration() == that.getDuration() && Objects.equal(getTask(), that.getTask()) && Objects.equal(getRunId(), that.getRunId()) && getStatus() == that.getStatus() && Objects.equal(getInterval(), that.getInterval()) && Objects.equal(getStartTime(), that.getStartTime()) && Objects.equal(getEndTime(), that.getEndTime()) && Objects.equal(getDesc(), that.getDesc()) && Objects.equal(getTableWriter(), that.getTableWriter());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getTask(), getRunId(), getStatus(), getInterval(), getStartTime(), getEndTime(), getDuration(), getDesc(), getTableWriter());
    }

    public Task getTask() {
        return task;
    }

    public void setTask(Task task) {
        this.task = task;
    }

    public String getRunId() {
        return runId;
    }

    public void setRunId(String runId) {
        this.runId = runId;
    }

    public TaskRunningStatus getStatus() {
        return status;
    }

    public void setStatus(TaskRunningStatus status) {
        this.status = status;
    }

    public TimeInterval getInterval() {
        return interval;
    }

    public void setInterval(TimeInterval interval) {
        this.interval = interval;
    }

    public LocalDateTime getStartTime() {
        return startTime;
    }

    public void setStartTime(LocalDateTime startTime) {
        this.startTime = startTime;
    }

    public LocalDateTime getEndTime() {
        return endTime;
    }

    public void setEndTime(LocalDateTime endTime) {
        this.endTime = endTime;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public List<TableRunning> getTableWriter() {
        return tableWriter;
    }

}
